home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / HFS_FS.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  12KB  |  325 lines

  1. /* 
  2.  * linux/include/linux/hfs_fs.h
  3.  *
  4.  * Copyright (C) 1995-1997  Paul H. Hargrove
  5.  * This file may be distributed under the terms of the GNU Public License.
  6.  *
  7.  * The source code distribution of the Columbia AppleTalk Package for
  8.  * UNIX, version 6.0, (CAP) was used as a specification of the
  9.  * location and format of files used by CAP's Aufs.  No code from CAP
  10.  * appears in hfs_fs.  hfs_fs is not a work ``derived'' from CAP in
  11.  * the sense of intellectual property law.
  12.  *
  13.  * The source code distributions of Netatalk, versions 1.3.3b2 and
  14.  * 1.4b2, were used as a specification of the location and format of
  15.  * files used by Netatalk's afpd.  No code from Netatalk appears in
  16.  * hfs_fs.  hfs_fs is not a work ``derived'' from Netatalk in the
  17.  * sense of intellectual property law.
  18.  */
  19.  
  20. #ifndef _LINUX_HFS_FS_H
  21. #define _LINUX_HFS_FS_H
  22.  
  23. #include <linux/hfs_sysdep.h>
  24.  
  25. /* magic numbers for Apple Double header files */
  26. #define HFS_DBL_MAGIC        0x00051607
  27. #define HFS_SNGL_MAGIC        0x00051600
  28. #define HFS_HDR_VERSION_1    0x00010000
  29. #define HFS_HDR_VERSION_2    0x00020000
  30.  
  31. /* magic numbers for various internal structures */
  32. #define HFS_INO_MAGIC        0x4821
  33. #define HFS_SB_MAGIC        0x4822
  34.  
  35. /* The space used for the AppleDouble or AppleSingle headers */
  36. #define HFS_DBL_HDR_LEN        1024
  37.  
  38. /* The space used for the Netatalk header */
  39. #define HFS_NAT_HDR_LEN        1024  /* 589 for an exact match */
  40.  
  41. /* Macros to extract CNID and file "type" from the Linux inode number */
  42. #define HFS_CNID(X)    ((X) & 0x3FFFFFFF)
  43. #define HFS_ITYPE(X)    ((X) & 0xC0000000)
  44.  
  45. /* Macros to enumerate types */
  46. #define HFS_ITYPE_TO_INT(X)    ((X) >> 30)
  47. #define HFS_INT_TO_ITYPE(X)    ((X) << 30)
  48.  
  49. /* generic ITYPEs */
  50. #define HFS_ITYPE_0    0x00000000
  51. #define HFS_ITYPE_1    0x40000000
  52. #define HFS_ITYPE_2    0x80000000
  53. #define HFS_ITYPE_3    0xC0000000
  54. #define HFS_ITYPE_NORM    HFS_ITYPE_0    /* "normal" directory or file */
  55.  
  56. /* ITYPEs for CAP */
  57. #define HFS_CAP_NORM    HFS_ITYPE_0    /* data fork or normal directory */
  58. #define HFS_CAP_DATA    HFS_ITYPE_0    /* data fork of file */
  59. #define HFS_CAP_NDIR    HFS_ITYPE_0    /* normal directory */
  60. #define HFS_CAP_FNDR    HFS_ITYPE_1    /* finder info for file or dir */
  61. #define HFS_CAP_RSRC    HFS_ITYPE_2    /* resource fork of file */
  62. #define HFS_CAP_RDIR    HFS_ITYPE_2    /* .resource directory */
  63. #define HFS_CAP_FDIR    HFS_ITYPE_3    /* .finderinfo directory */
  64.  
  65. /* ITYPEs for Apple Double */
  66. #define HFS_DBL_NORM    HFS_ITYPE_0    /* data fork or directory */
  67. #define HFS_DBL_DATA    HFS_ITYPE_0    /* data fork of file */
  68. #define HFS_DBL_DIR    HFS_ITYPE_0    /* directory */
  69. #define HFS_DBL_HDR    HFS_ITYPE_1    /* AD header of file or dir */
  70.  
  71. /* ITYPEs for netatalk */
  72. #define HFS_NAT_NORM    HFS_ITYPE_0    /* data fork or directory */
  73. #define HFS_NAT_DATA    HFS_ITYPE_0    /* data fork of file */
  74. #define HFS_NAT_NDIR    HFS_ITYPE_0    /* normal directory */
  75. #define HFS_NAT_HDR    HFS_ITYPE_1    /* AD header of file or dir */
  76. #define HFS_NAT_HDIR    HFS_ITYPE_2    /* directory holding AD headers */
  77.  
  78. /* ITYPEs for Apple Single */
  79. #define HFS_SGL_NORM    HFS_ITYPE_0    /* AppleSingle file or directory */
  80. #define HFS_SGL_SNGL    HFS_ITYPE_0    /* AppleSingle file */
  81. #define HFS_SGL_DIR    HFS_ITYPE_0    /* directory */
  82. #define HFS_SGL_DINF    HFS_ITYPE_1    /* %DirInfo for directory */
  83.  
  84. /* IDs for elements of an AppleDouble or AppleSingle header */
  85. #define HFS_HDR_DATA    1
  86. #define HFS_HDR_RSRC    2
  87. #define HFS_HDR_FNAME    3
  88. #define HFS_HDR_COMNT    4
  89. #define HFS_HDR_BWICN    5
  90. #define HFS_HDR_CICON    6
  91. #define HFS_HDR_OLDI    7
  92. #define HFS_HDR_DATES    8
  93. #define HFS_HDR_FINFO    9
  94. #define HFS_HDR_MACI    10
  95. #define HFS_HDR_MAX    10
  96.  
  97. /*
  98.  * There are three time systems.  All three are based on seconds since
  99.  * a particular time/date.
  100.  *    Unix:    unsigned lil-endian since 00:00 GMT, Jan. 1, 1970
  101.  *    mac:    unsigned big-endian since 00:00 GMT, Jan. 1, 1904
  102.  *    header:      SIGNED big-endian since 00:00 GMT, Jan. 1, 2000
  103.  *
  104.  */
  105. #define hfs_h_to_mtime(ARG)    htonl((hfs_s32)ntohl(ARG)+3029529600U)
  106. #define hfs_m_to_htime(ARG)    ((hfs_s32)htonl(ntohl(ARG)-3029529600U))
  107. #define hfs_h_to_utime(ARG)    ((hfs_s32)hfs_to_utc(ntohl(ARG)+946684800U))
  108. #define hfs_u_to_htime(ARG)    ((hfs_s32)htonl(hfs_from_utc(ARG)-946684800U))
  109. #define hfs_u_to_mtime(ARG)    htonl(hfs_from_utc(ARG)+2082844800U)
  110. #define hfs_m_to_utime(ARG)    (hfs_to_utc(ntohl(ARG)-2082844800U))
  111.  
  112. /*======== Data structures kept in memory ========*/
  113.  
  114. /*
  115.  * A descriptor for a single entry within the header of an
  116.  * AppleDouble or AppleSingle header file.
  117.  * An array of these make up a table of contents for the file.
  118.  */
  119. struct hfs_hdr_descr {
  120.     hfs_u32    id;    /* The Apple assigned ID for the entry type */
  121.     hfs_u32    offset;    /* The offset to reach the entry */
  122.     hfs_u32    length;    /* The length of the entry */
  123. };
  124.  
  125. /*
  126.  * The info needed to reconstruct a given header layout
  127.  */
  128. struct hfs_hdr_layout {
  129.     hfs_u32        magic;            /* AppleSingle or AppleDouble */
  130.     hfs_u32        version;        /* 0x00010000 or 0x00020000 */
  131.     hfs_u16        entries;        /* How many entries used */
  132.     struct hfs_hdr_descr    
  133.             descr[HFS_HDR_MAX];    /* Descriptors */
  134.     struct hfs_hdr_descr    
  135.             *order[HFS_HDR_MAX];    /* 'descr' ordered by offset */
  136. };
  137.  
  138. /* 
  139.  * Default header layout for Netatalk
  140.  */
  141. struct hfs_nat_hdr {
  142.     hfs_lword_t    magic;
  143.     hfs_lword_t    version;
  144.     hfs_byte_t    homefs[16];
  145.     hfs_word_t    entries;
  146.     hfs_byte_t    descrs[60];
  147.     hfs_byte_t    real_name[255];    /* id=3 */
  148.     hfs_byte_t    comment[200];    /* id=4 XXX: not yet implemented */
  149.     hfs_lword_t    create_time;    /* \       */
  150.     hfs_lword_t    modify_time;    /*  |      */
  151.     hfs_lword_t    backup_time;    /*  | id=7 */
  152.     hfs_word_t    filler;        /*  |      */
  153.     hfs_word_t    attr;        /* /       */
  154.     hfs_byte_t    finderinfo[32]; /* id=9 */
  155. };
  156.  
  157. /* 
  158.  * Default header layout for AppleDouble
  159.  */
  160. struct hfs_dbl_hdr {
  161.     hfs_lword_t    magic;
  162.     hfs_lword_t    version;
  163.     hfs_byte_t    filler[16];
  164.     hfs_word_t    entries;
  165.     hfs_byte_t    descrs[12*HFS_HDR_MAX];
  166.     hfs_u32        create_time;    /* \       */
  167.     hfs_u32        modify_time;    /*  | id=8 */
  168.     hfs_u32        backup_time;    /*  |       */
  169.     hfs_u32        access_time;    /* /       */
  170.     hfs_u8        finderinfo[32]; /* id=9 */
  171.     hfs_u32        fileinfo;    /* id=10 */
  172.     hfs_u8        real_name[32];    /* id=3 */
  173.     hfs_u8        comment[200];    /* id=4 XXX: not yet implemented */
  174. };
  175.  
  176. /* finder metadata for CAP */
  177. struct hfs_cap_info {
  178.     hfs_byte_t    fi_fndr[32];    /* Finder's info */
  179.     hfs_word_t    fi_attr;    /* AFP attributes */
  180. #define HFS_AFP_WRI        0x020    /* Write inhibit bit */
  181. #define HFS_AFP_RNI        0x080    /* Rename inhibit bit (AFP >= 2.0) */
  182. #define HFS_AFP_DEI        0x100    /* Delete inhibit bit (AFP >= 2.0) */
  183. #define HFS_AFP_RDONLY    (    HFS_AFP_WRI|HFS_AFP_RNI|HFS_AFP_DEI)
  184.     hfs_byte_t    fi_magic1;    /* Magic number: */
  185. #define HFS_CAP_MAGIC1        0xFF
  186.     hfs_byte_t    fi_version;    /* Version of this structure: */
  187. #define HFS_CAP_VERSION        0x10
  188.     hfs_byte_t    fi_magic;    /* Another magic number: */
  189. #define HFS_CAP_MAGIC        0xDA
  190.     hfs_byte_t    fi_bitmap;    /* Bitmap of which names are valid: */
  191. #define HFS_CAP_SHORTNAME    0x01
  192. #define HFS_CAP_LONGNAME    0x02
  193.     hfs_byte_t    fi_shortfilename[12+1];    /* "short name" (unused) */
  194.     hfs_byte_t    fi_macfilename[32+1];    /* Original (Macintosh) name */
  195.     hfs_byte_t    fi_comln;    /* Length of comment (always 0) */
  196.     hfs_byte_t    fi_comnt[200];    /* Finder comment (unused) */
  197.     /* optional:     used by aufs only if compiled with USE_MAC_DATES */
  198.     hfs_byte_t    fi_datemagic;    /* Magic number for dates extension: */
  199. #define HFS_CAP_DMAGIC        0xDA
  200.     hfs_byte_t    fi_datevalid;    /* Bitmap of which dates are valid: */
  201. #define HFS_CAP_MDATE        0x01
  202. #define HFS_CAP_CDATE        0x02
  203.     hfs_lword_t    fi_ctime;    /* Creation date (in AFP format) */
  204.     hfs_lword_t    fi_mtime;    /* Modify date (in AFP format) */
  205.     hfs_lword_t    fi_utime;    /* Un*x time of last mtime change */
  206.     hfs_byte_t    pad;
  207. };
  208.  
  209. #ifdef __KERNEL__
  210.  
  211. typedef ssize_t hfs_rwret_t;
  212. typedef size_t hfs_rwarg_t;
  213.  
  214. #include <asm/uaccess.h>
  215.  
  216. /* Some forward declarations */
  217. struct hfs_fork;
  218. struct hfs_cat_key;
  219. struct hfs_cat_entry;
  220. extern struct hfs_cat_entry *hfs_cat_get(struct hfs_mdb *,
  221.                      const struct hfs_cat_key *);
  222.  
  223. /* dir.c */
  224. extern hfs_rwret_t hfs_dir_read(struct file *, char *, hfs_rwarg_t,
  225.                 loff_t *);
  226. extern int hfs_create(struct inode *, struct dentry *, int);
  227. extern int hfs_mkdir(struct inode *, struct dentry *, int);
  228. extern int hfs_mknod(struct inode *, struct dentry *, int, int);
  229. extern int hfs_unlink(struct inode *, struct dentry *);
  230. extern int hfs_rmdir(struct inode *, struct dentry *);
  231. extern int hfs_rename(struct inode *, struct dentry *,
  232.               struct inode *, struct dentry *);
  233.  
  234. /* dir_cap.c */
  235. extern const struct hfs_name hfs_cap_reserved1[];
  236. extern const struct hfs_name hfs_cap_reserved2[];
  237. extern struct inode_operations hfs_cap_ndir_inode_operations;
  238. extern struct inode_operations hfs_cap_fdir_inode_operations;
  239. extern struct inode_operations hfs_cap_rdir_inode_operations;
  240. extern void hfs_cap_drop_dentry(struct dentry *, const ino_t);
  241.  
  242. /* dir_dbl.c */
  243. extern const struct hfs_name hfs_dbl_reserved1[];
  244. extern const struct hfs_name hfs_dbl_reserved2[];
  245. extern struct inode_operations hfs_dbl_dir_inode_operations;
  246. extern void hfs_dbl_drop_dentry(struct dentry *, const ino_t);
  247.  
  248. /* dir_nat.c */
  249. extern const struct hfs_name hfs_nat_reserved1[];
  250. extern const struct hfs_name hfs_nat_reserved2[];
  251. extern struct inode_operations hfs_nat_ndir_inode_operations;
  252. extern struct inode_operations hfs_nat_hdir_inode_operations;
  253. extern void hfs_nat_drop_dentry(struct dentry *, const ino_t);
  254.  
  255. /* dir_sngl.c */
  256. extern const struct hfs_name hfs_sngl_reserved1[];
  257. extern const struct hfs_name hfs_sngl_reserved2[];
  258. extern struct inode_operations hfs_sngl_dir_inode_operations;
  259.  
  260. /* file.c */
  261. extern hfs_s32 hfs_do_read(struct inode *, struct hfs_fork *, hfs_u32,
  262.                char *, hfs_u32, int);
  263. extern hfs_s32 hfs_do_write(struct inode *, struct hfs_fork *, hfs_u32,
  264.                 const char *, hfs_u32);
  265. extern void hfs_file_fix_mode(struct hfs_cat_entry *entry);
  266. extern struct inode_operations hfs_file_inode_operations;
  267.  
  268. /* file_cap.c */
  269. extern struct inode_operations hfs_cap_info_inode_operations;
  270.  
  271. /* file_hdr.c */
  272. extern struct inode_operations hfs_hdr_inode_operations;
  273. extern const struct hfs_hdr_layout hfs_dbl_fil_hdr_layout;
  274. extern const struct hfs_hdr_layout hfs_dbl_dir_hdr_layout;
  275. extern const struct hfs_hdr_layout hfs_nat_hdr_layout;
  276. extern const struct hfs_hdr_layout hfs_sngl_hdr_layout;
  277.  
  278. /* inode.c */
  279. extern void hfs_put_inode(struct inode *);
  280. extern int hfs_notify_change(struct dentry *, struct iattr *);
  281. extern struct inode *hfs_iget(struct hfs_cat_entry *, ino_t, struct dentry *);
  282.  
  283. extern void hfs_cap_ifill(struct inode *, ino_t);
  284. extern void hfs_dbl_ifill(struct inode *, ino_t);
  285. extern void hfs_nat_ifill(struct inode *, ino_t);
  286. extern void hfs_sngl_ifill(struct inode *, ino_t);
  287.  
  288. /* super.c */
  289. extern struct super_block *hfs_read_super(struct super_block *,void *,int);
  290. extern int init_hfs_fs(void);
  291.  
  292. /* trans.c */
  293. extern void hfs_colon2mac(struct hfs_name *, const char *, int);
  294. extern void hfs_prcnt2mac(struct hfs_name *, const char *, int);
  295. extern void hfs_triv2mac(struct hfs_name *, const char *, int);
  296. extern void hfs_latin2mac(struct hfs_name *, const char *, int);
  297. extern int hfs_mac2cap(char *, const struct hfs_name *);
  298. extern int hfs_mac2nat(char *, const struct hfs_name *);
  299. extern int hfs_mac2latin(char *, const struct hfs_name *);
  300. extern int hfs_mac2seven(char *, const struct hfs_name *);
  301. extern int hfs_mac2eight(char *, const struct hfs_name *);
  302. extern int hfs_mac2alpha(char *, const struct hfs_name *);
  303. extern int hfs_mac2triv(char *, const struct hfs_name *);
  304. extern void hfs_tolower(unsigned char *, int);
  305.  
  306. #define    HFS_I(X)    (&((X)->u.hfs_i))
  307. #define    HFS_SB(X)    (&((X)->u.hfs_sb))
  308.  
  309. extern __inline__ void hfs_nameout(struct inode *dir, struct hfs_name *out,
  310.                    const char *in, int len) {
  311.     HFS_SB(dir->i_sb)->s_nameout(out, in, len);
  312. }
  313.  
  314. extern __inline__ int hfs_namein(struct inode *dir, char *out,
  315.                  const struct hfs_name *in) {
  316.     int len = HFS_SB(dir->i_sb)->s_namein(out, in);
  317.     if (HFS_SB(dir->i_sb)->s_lowercase) {
  318.         hfs_tolower(out, len);
  319.     }
  320.     return len;
  321. }
  322.  
  323. #endif /* __KERNEL__ */
  324. #endif
  325.